package com.eascs.admin.common.excel;

import java.io.File;
import java.io.FileOutputStream;
import java.util.List;

import org.springframework.stereotype.Service;

import com.eascs.app.exception.ControllerException;
import com.eascs.app.log.Logger;
import com.eascs.app.log.LoggerFactory;
import com.eascs.common.doc.excel.ExcelApiHelper;
import com.eascs.common.util.IoUtil;


@Service
public class ExcelService {

	private final Logger logger = LoggerFactory.getLogger(ExcelService.class);	
	/*
	 * 生成excel
	 * 参数：数据，源文件，输出文件，excel包含的列，需要统计的列，excel标题
	 */
	public void writeByDate( String soucreFileName, String outPath, int col,int[] arr,List<String> title,int sheetIndex,int rowIndex,int columnIndex,List<Object[]> data) {
		//List<Object[]> data = baseService.findObjectsList(sql,Date);
		IoUtil.createDirectorieIfMissing(new File(outPath).getParentFile());
		try {
			ExcelApiHelper.writeHandle(new FileOutputStream(outPath), ExcelService.class.getResourceAsStream(soucreFileName), new BankRowWriteHandler(data, col,arr,title,sheetIndex,rowIndex,columnIndex));
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			throw new ControllerException(e);
		}
	}
	
}
